#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstring>
#define mod 998244353
using namespace std;
long long f[1002][40002];
long long a[1002];
int main(){
    int n;
    cin>>n;
    long long maxn=0;
    long long minn=0x3f3f3f3f;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        maxn=max(maxn,a[i]);
        minn=min(minn,a[i]);
    }
    int py=maxn-minn;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<i;j++){
            f[i][a[i]-a[j]+py]+=f[j][a[i]-a[j]+py]+1;
            f[i][a[i]-a[j]+py]%=mod;
            ans+=(f[j][a[i]-a[j]+py]+1);
            ans%=mod;
        }
    }
    cout<<(ans+n)%mod;
    return 0;
}